<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>青骄第二课堂禁毒知识辅助脚本 - Xzap&#39;s 缓存区</title><meta name="Description" content=""><meta property="og:title" content="青骄第二课堂禁毒知识辅助脚本" />
<meta property="og:description" content="又是让学生学禁毒。城里学校都是发给家长让家长做。我们学校就安排给电脑老师。没辙，就带学生在信息课上做呗。但总有漏网之鱼，只好写个脚本来完善一下。人不多那就随便写写算了，能跑就行。" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://xzap.gitee.io/posts/2class/" /><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2023-11-15T20:52:53+08:00" />
<meta property="article:modified_time" content="2023-11-15T20:52:53+08:00" /><meta property="og:site_name" content="Xzap&#39;s 缓存区" />

<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="青骄第二课堂禁毒知识辅助脚本"/>
<meta name="twitter:description" content="又是让学生学禁毒。城里学校都是发给家长让家长做。我们学校就安排给电脑老师。没辙，就带学生在信息课上做呗。但总有漏网之鱼，只好写个脚本来完善一下。人不多那就随便写写算了，能跑就行。"/>
<meta name="application-name" content="Xzap&#39;s 缓存区">
<meta name="apple-mobile-web-app-title" content="Xzap&#39;s 缓存区"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="http://xzap.gitee.io/posts/2class/" /><link rel="prev" href="http://xzap.gitee.io/posts/img2pdf/" /><link rel="next" href="http://xzap.gitee.io/posts/crack_sublime/" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.1/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "青骄第二课堂禁毒知识辅助脚本",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "http:\/\/xzap.gitee.io\/posts\/2class\/"
        },"genre": "posts","keywords": "Python, Playwright","wordcount":  1243 ,
        "url": "http:\/\/xzap.gitee.io\/posts\/2class\/","datePublished": "2023-11-15T20:52:53+08:00","dateModified": "2023-11-15T20:52:53+08:00","publisher": {
            "@type": "Organization",
            "name": ""},"author": {
                "@type": "Person",
                "name": "xzap"
            },"description": ""
    }
    </script></head>
    <body data-header-desktop="fixed" data-header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="Xzap&#39;s 缓存区">Xzap&#39;s 缓存区</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="/docs/"> 文档 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="Xzap&#39;s 缓存区">Xzap&#39;s 缓存区</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="/docs/" title="">文档</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
            </a></div>
    </div>
</header><div class="search-dropdown desktop">
        <div id="search-dropdown-desktop"></div>
    </div>
    <div class="search-dropdown mobile">
        <div id="search-dropdown-mobile"></div>
    </div><main class="main">
                <div class="container"><article class="page single"><h1 class="single-title animate__animated animate__flipInX">青骄第二课堂禁毒知识辅助脚本</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="https://xzap.gitee.io" title="Author" target="_blank" rel="noopener noreffer author" class="author"><i class="fas fa-user-circle fa-fw" aria-hidden="true"></i>xzap</a>
</span>&nbsp;<span class="post-category">收录于 <a href="/categories/python/"><i class="far fa-folder fa-fw" aria-hidden="true"></i>Python</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw" aria-hidden="true"></i>&nbsp;<time datetime="2023-11-15">2023-11-15</time>&nbsp;<i class="fas fa-pencil-alt fa-fw" aria-hidden="true"></i>&nbsp;约 1243 字&nbsp;
                <i class="far fa-clock fa-fw" aria-hidden="true"></i>&nbsp;预计阅读 3 分钟&nbsp;</div>
        </div><div class="content" id="content"><p>又是让学生学禁毒。城里学校都是发给家长让家长做。我们学校就安排给电脑老师。没辙，就带学生在信息课上做呗。但总有漏网之鱼，只好写个脚本来完善一下。人不多那就随便写写算了，能跑就行。</p>
<p>先是用 <code>python -m playwright codegen -o out.py  --target python -b ff</code> 用PlayWright自带录制工具。录制一遍登录。然后再用开发者工具直接把提交考试的那个post信息找出来，合在一起就完成了。</p>
<p>中间还是好多坑：</p>
<ol>
<li>首先用 chromium 接口死活登录不上，最后用了 firefox 才顺利登录。</li>
<li>登录的时候有个阿里云的无验证码验证，也就是滑条。一开始还不出现。10几个人后就开始出现了。然后很简单几行代码找到坐标，滑动一下就可以了。10几个人后阿里云的ai可能发现滑动太平滑了，又要点击验证。只好再制作个滑动路径，使得每次的滑动路径都不一样。总算跑完了那100多人。速度就奇慢了，完成就好。懒得优化了。反正我完成了，哈哈。</li>
<li>上次写那个青少年普法做了件脱裤子放屁的事情。还把cookie转到requests里再进行刷。其实完全可以直接用 <code>page.request.post()</code> 就好了。真是多此一举。</li>
</ol>
<p>找一个文本文件放入用户名姓名和密码，注意要另存为utf-8编码格式。保存为 <strong>s.csv</strong> 放在同目录下。</p>
<pre tabindex="0"><code>用户名1,密码1
用户名2,密码2
用户名3,密码3
……
</code></pre><p>直接上代码：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">  1
</span><span class="lnt">  2
</span><span class="lnt">  3
</span><span class="lnt">  4
</span><span class="lnt">  5
</span><span class="lnt">  6
</span><span class="lnt">  7
</span><span class="lnt">  8
</span><span class="lnt">  9
</span><span class="lnt"> 10
</span><span class="lnt"> 11
</span><span class="lnt"> 12
</span><span class="lnt"> 13
</span><span class="lnt"> 14
</span><span class="lnt"> 15
</span><span class="lnt"> 16
</span><span class="lnt"> 17
</span><span class="lnt"> 18
</span><span class="lnt"> 19
</span><span class="lnt"> 20
</span><span class="lnt"> 21
</span><span class="lnt"> 22
</span><span class="lnt"> 23
</span><span class="lnt"> 24
</span><span class="lnt"> 25
</span><span class="lnt"> 26
</span><span class="lnt"> 27
</span><span class="lnt"> 28
</span><span class="lnt"> 29
</span><span class="lnt"> 30
</span><span class="lnt"> 31
</span><span class="lnt"> 32
</span><span class="lnt"> 33
</span><span class="lnt"> 34
</span><span class="lnt"> 35
</span><span class="lnt"> 36
</span><span class="lnt"> 37
</span><span class="lnt"> 38
</span><span class="lnt"> 39
</span><span class="lnt"> 40
</span><span class="lnt"> 41
</span><span class="lnt"> 42
</span><span class="lnt"> 43
</span><span class="lnt"> 44
</span><span class="lnt"> 45
</span><span class="lnt"> 46
</span><span class="lnt"> 47
</span><span class="lnt"> 48
</span><span class="lnt"> 49
</span><span class="lnt"> 50
</span><span class="lnt"> 51
</span><span class="lnt"> 52
</span><span class="lnt"> 53
</span><span class="lnt"> 54
</span><span class="lnt"> 55
</span><span class="lnt"> 56
</span><span class="lnt"> 57
</span><span class="lnt"> 58
</span><span class="lnt"> 59
</span><span class="lnt"> 60
</span><span class="lnt"> 61
</span><span class="lnt"> 62
</span><span class="lnt"> 63
</span><span class="lnt"> 64
</span><span class="lnt"> 65
</span><span class="lnt"> 66
</span><span class="lnt"> 67
</span><span class="lnt"> 68
</span><span class="lnt"> 69
</span><span class="lnt"> 70
</span><span class="lnt"> 71
</span><span class="lnt"> 72
</span><span class="lnt"> 73
</span><span class="lnt"> 74
</span><span class="lnt"> 75
</span><span class="lnt"> 76
</span><span class="lnt"> 77
</span><span class="lnt"> 78
</span><span class="lnt"> 79
</span><span class="lnt"> 80
</span><span class="lnt"> 81
</span><span class="lnt"> 82
</span><span class="lnt"> 83
</span><span class="lnt"> 84
</span><span class="lnt"> 85
</span><span class="lnt"> 86
</span><span class="lnt"> 87
</span><span class="lnt"> 88
</span><span class="lnt"> 89
</span><span class="lnt"> 90
</span><span class="lnt"> 91
</span><span class="lnt"> 92
</span><span class="lnt"> 93
</span><span class="lnt"> 94
</span><span class="lnt"> 95
</span><span class="lnt"> 96
</span><span class="lnt"> 97
</span><span class="lnt"> 98
</span><span class="lnt"> 99
</span><span class="lnt">100
</span><span class="lnt">101
</span><span class="lnt">102
</span><span class="lnt">103
</span><span class="lnt">104
</span><span class="lnt">105
</span><span class="lnt">106
</span><span class="lnt">107
</span><span class="lnt">108
</span><span class="lnt">109
</span><span class="lnt">110
</span><span class="lnt">111
</span><span class="lnt">112
</span><span class="lnt">113
</span><span class="lnt">114
</span><span class="lnt">115
</span><span class="lnt">116
</span><span class="lnt">117
</span><span class="lnt">118
</span><span class="lnt">119
</span><span class="lnt">120
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-Python" data-lang="Python"><span class="line"><span class="cl"><span class="ch">#!/usr/bin/env python</span>
</span></span><span class="line"><span class="cl"><span class="c1"># -*- coding: utf-8 -*-</span>
</span></span><span class="line"><span class="cl"><span class="c1"># @Date    : 2023-11-15 19:18:10</span>
</span></span><span class="line"><span class="cl"><span class="c1"># @Author  : Xzap (xzap@163.com)</span>
</span></span><span class="line"><span class="cl"><span class="c1"># @Link    : https://xzap.gitee.io</span>
</span></span><span class="line"><span class="cl"><span class="c1"># @Version : $Id$</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kn">from</span> <span class="nn">playwright.sync_api</span> <span class="kn">import</span> <span class="n">Playwright</span><span class="p">,</span> <span class="n">sync_playwright</span><span class="p">,</span> <span class="n">expect</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">time</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">re</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">random</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&#34;s.csv&#34;</span><span class="p">,</span><span class="s2">&#34;r&#34;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&#34;utf-8&#34;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">    <span class="n">s1</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&#34;</span><span class="se">\n</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">s</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&#34;,&#34;</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">s1</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">make_tracks</span><span class="p">(</span><span class="n">num</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">num2</span> <span class="o">=</span> <span class="n">num</span> <span class="o">+</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="mi">10</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">a</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">10</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">a2</span> <span class="o">=</span> <span class="n">num2</span> <span class="o">//</span> <span class="n">a</span>
</span></span><span class="line"><span class="cl">    <span class="n">a3</span> <span class="o">=</span> <span class="p">[]</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">a</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="n">a3</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="n">a2</span><span class="o">-</span><span class="mi">30</span><span class="p">,</span><span class="n">a2</span><span class="o">+</span><span class="mi">30</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">    <span class="n">cha</span> <span class="o">=</span> <span class="n">num2</span> <span class="o">-</span> <span class="nb">sum</span><span class="p">(</span><span class="n">a3</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">a3</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">a3</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">cha</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">a3</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">cancel_request</span><span class="p">(</span><span class="n">route</span><span class="p">,</span><span class="n">request</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">route</span><span class="o">.</span><span class="n">abort</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">login</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">passwd</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span> <span class="o">=</span> <span class="n">context</span><span class="o">.</span><span class="n">new_page</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&#34;(\.png)|(\.jpg)&#34;</span><span class="p">),</span><span class="n">cancel_request</span><span class="p">)</span> <span class="c1"># 不加载图片</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://www.2-class.com/&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">rt</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s1">&#39;reqtoken:&#34;(.*?)&#34;&#39;</span><span class="p">,</span>  <span class="n">page</span><span class="o">.</span><span class="n">content</span><span class="p">())</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># print (rt)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">get_by_role</span><span class="p">(</span><span class="s2">&#34;button&#34;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&#34;登 录&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">click</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">get_by_placeholder</span><span class="p">(</span><span class="s2">&#34;请输入登录账号&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">click</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">get_by_placeholder</span><span class="p">(</span><span class="s2">&#34;请输入登录账号&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">get_by_placeholder</span><span class="p">(</span><span class="s2">&#34;请输入密码&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">click</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">get_by_placeholder</span><span class="p">(</span><span class="s2">&#34;请输入密码&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">passwd</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">get_by_label</span><span class="p">(</span><span class="s2">&#34;自动登录&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">get_by_role</span><span class="p">(</span><span class="s2">&#34;button&#34;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&#34;确 定&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">click</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.pause()</span>
</span></span><span class="line"><span class="cl">    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="k">try</span> <span class="p">:</span>
</span></span><span class="line"><span class="cl">        <span class="n">cc</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">locator</span><span class="p">(</span><span class="s2">&#34;#nc_1_nocaptcha&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="n">cc</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span> 
</span></span><span class="line"><span class="cl">            <span class="n">slider</span> <span class="o">=</span>  <span class="n">page</span><span class="o">.</span><span class="n">locator</span><span class="p">(</span><span class="s2">&#34;#nc_1_n1z&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">bounding_box</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">            <span class="c1"># print(slider)</span>
</span></span><span class="line"><span class="cl">            <span class="n">page</span><span class="o">.</span><span class="n">mouse</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">slider</span><span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">]),</span> <span class="n">y</span><span class="o">=</span><span class="n">slider</span><span class="p">[</span><span class="s1">&#39;y&#39;</span><span class="p">]</span><span class="o">+</span><span class="n">slider</span><span class="p">[</span><span class="s1">&#39;height&#39;</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">page</span><span class="o">.</span><span class="n">mouse</span><span class="o">.</span><span class="n">down</span><span class="p">()</span>        
</span></span><span class="line"><span class="cl">            <span class="n">page</span><span class="o">.</span><span class="n">wait_for_timeout</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">tracks</span> <span class="o">=</span> <span class="n">make_tracks</span><span class="p">(</span><span class="mi">400</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">xc</span> <span class="o">=</span> <span class="mi">0</span>
</span></span><span class="line"><span class="cl">            <span class="k">for</span> <span class="n">track</span> <span class="ow">in</span> <span class="n">tracks</span> <span class="p">:</span>
</span></span><span class="line"><span class="cl">                <span class="n">xc</span> <span class="o">+=</span> <span class="n">track</span>
</span></span><span class="line"><span class="cl">                <span class="n">page</span><span class="o">.</span><span class="n">mouse</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">slider</span><span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">])</span> <span class="o">+</span> <span class="n">xc</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">slider</span><span class="p">[</span><span class="s1">&#39;y&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">slider</span><span class="p">[</span><span class="s1">&#39;height&#39;</span><span class="p">]</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span><span class="n">steps</span><span class="o">=</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">10</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">                <span class="n">page</span><span class="o">.</span><span class="n">wait_for_timeout</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">6</span><span class="p">)</span><span class="o">*</span><span class="mi">10</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">page</span><span class="o">.</span><span class="n">mouse</span><span class="o">.</span><span class="n">up</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="k">except</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">        <span class="nb">print</span> <span class="p">(</span><span class="s2">&#34;No slider!&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">get_by_role</span><span class="p">(</span><span class="s2">&#34;button&#34;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&#34;我的课程&#34;</span><span class="p">)</span><span class="o">.</span><span class="n">click</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1"># 五年级第一课</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://www.2-class.com/courses/1575&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&#34;courseId&#34;</span><span class="p">:</span><span class="mi">1575</span><span class="p">,</span><span class="s2">&#34;reqtoken&#34;</span><span class="p">:</span><span class="n">rt</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="s2">&#34;https://www.2-class.com/api/course/addCoursePlayPV&#34;</span><span class="p">,</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://www.2-class.com/courses/exams/1575&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&#34;courseId&#34;</span><span class="p">:</span><span class="s2">&#34;1575&#34;</span><span class="p">,</span><span class="s2">&#34;examCommitReqDataList&#34;</span><span class="p">:[{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="mi">0</span><span class="p">},{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="mi">2</span><span class="p">},{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="mi">2</span><span class="p">},{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="mi">3</span><span class="p">},{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="s2">&#34;0,1,2,3&#34;</span><span class="p">}],</span><span class="s2">&#34;exam&#34;</span><span class="p">:</span><span class="s2">&#34;course&#34;</span><span class="p">,</span><span class="s2">&#34;reqtoken&#34;</span><span class="p">:</span><span class="n">rt</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="s2">&#34;https://www.2-class.com/api/exam/commit&#34;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://www.2-class.com/drugControlClassroom/courses&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1"># 五年级第二课</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://www.2-class.com/courses/1576&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&#34;courseId&#34;</span><span class="p">:</span><span class="mi">1576</span><span class="p">,</span><span class="s2">&#34;reqtoken&#34;</span><span class="p">:</span><span class="n">rt</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="s2">&#34;https://www.2-class.com/api/course/addCoursePlayPV&#34;</span><span class="p">,</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://www.2-class.com/courses/exams/1576&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&#34;courseId&#34;</span><span class="p">:</span><span class="s2">&#34;1576&#34;</span><span class="p">,</span><span class="s2">&#34;examCommitReqDataList&#34;</span><span class="p">:[{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="mi">2</span><span class="p">},{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="mi">3</span><span class="p">},{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="mi">1</span><span class="p">},{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="mi">1</span><span class="p">},{</span><span class="s2">&#34;examId&#34;</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span><span class="s2">&#34;answer&#34;</span><span class="p">:</span><span class="s2">&#34;0,2&#34;</span><span class="p">}],</span><span class="s2">&#34;exam&#34;</span><span class="p">:</span><span class="s2">&#34;course&#34;</span><span class="p">,</span><span class="s2">&#34;reqtoken&#34;</span><span class="p">:</span><span class="n">rt</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="s2">&#34;https://www.2-class.com/api/exam/commit&#34;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://www.2-class.com/drugControlClassroom/courses&#34;</span><span class="p">)</span>   
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1"># 六年级第一课</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.goto(&#34;https://www.2-class.com/courses/1577&#34;)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># data = {&#34;courseId&#34;:1577,&#34;reqtoken&#34;:rt}</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.request.post(url=&#34;https://www.2-class.com/api/course/addCoursePlayPV&#34;,data=data)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.goto(&#34;https://www.2-class.com/courses/exams/1577&#34;)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># data ={&#34;courseId&#34;:&#34;1577&#34;,&#34;examCommitReqDataList&#34;:[{&#34;examId&#34;:1,&#34;answer&#34;:3},{&#34;examId&#34;:2,&#34;answer&#34;:1},{&#34;examId&#34;:3,&#34;answer&#34;:3},{&#34;examId&#34;:4,&#34;answer&#34;:0},{&#34;examId&#34;:5,&#34;answer&#34;:&#34;0,1,2&#34;}],&#34;exam&#34;:&#34;course&#34;,&#34;reqtoken&#34;:rt}</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.request.post(url=&#34;https://www.2-class.com/api/exam/commit&#34;, data=data)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.goto(&#34;https://www.2-class.com/drugControlClassroom/courses&#34;)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1"># 六年级第二课</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.goto(&#34;https://www.2-class.com/courses/1578&#34;)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># data = {&#34;courseId&#34;:1578,&#34;reqtoken&#34;:rt}</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.request.post(url=&#34;https://www.2-class.com/api/course/addCoursePlayPV&#34;,data=data)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.goto(&#34;https://www.2-class.com/courses/exams/1578&#34;)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># data = {&#34;courseId&#34;:&#34;1578&#34;,&#34;examCommitReqDataList&#34;:[{&#34;examId&#34;:1,&#34;answer&#34;:0},{&#34;examId&#34;:2,&#34;answer&#34;:1},{&#34;examId&#34;:3,&#34;answer&#34;:0},{&#34;examId&#34;:4,&#34;answer&#34;:3},{&#34;examId&#34;:5,&#34;answer&#34;:&#34;0,1,3&#34;}],&#34;exam&#34;:&#34;course&#34;,&#34;reqtoken&#34;:rt}</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.request.post(url=&#34;https://www.2-class.com/api/exam/commit&#34;, data=data)</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># page.goto(&#34;https://www.2-class.com/drugControlClassroom/courses&#34;) </span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="s2">&#34;https://www.2-class.com/api/user/logout&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">page</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="n">playwright</span><span class="p">:</span> <span class="n">Playwright</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">    <span class="n">browser</span> <span class="o">=</span> <span class="n">playwright</span><span class="o">.</span><span class="n">firefox</span><span class="o">.</span><span class="n">launch</span><span class="p">(</span><span class="n">headless</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">context</span> <span class="o">=</span> <span class="n">browser</span><span class="o">.</span><span class="n">new_context</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">alln</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="n">num</span><span class="p">,</span><span class="n">i</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="nb">print</span> <span class="p">(</span><span class="s2">&#34;=&#34;</span><span class="o">*</span><span class="mi">50</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="nb">print</span> <span class="p">(</span><span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
</span></span><span class="line"><span class="cl">        <span class="nb">print</span> <span class="p">(</span><span class="sa">f</span><span class="s2">&#34;</span><span class="si">{</span><span class="n">num</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s2">/</span><span class="si">{</span><span class="n">alln</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="n">login</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="n">i</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">i</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># ---------------------</span>
</span></span><span class="line"><span class="cl">    <span class="n">context</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">    <span class="n">browser</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</span></span><span class="line"><span class="cl"><span class="k">with</span> <span class="n">sync_playwright</span><span class="p">()</span> <span class="k">as</span> <span class="n">playwright</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">    <span class="n">run</span><span class="p">(</span><span class="n">playwright</span><span class="p">)</span>
</span></span></code></pre></td></tr></table>
</div>
</div></div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2023-11-15</span>
            </div></div>
        <div class="post-info-line">
            <div class="post-info-md"></div>
            <div class="post-info-share">
                <span></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw" aria-hidden="true"></i>&nbsp;<a href="/tags/python/">Python</a>,&nbsp;<a href="/tags/playwright/">Playwright</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/posts/img2pdf/" class="prev" rel="prev" title="Python脚本将多张图片转成pdf文件"><i class="fas fa-angle-left fa-fw" aria-hidden="true"></i>Python脚本将多张图片转成pdf文件</a>
            <a href="/posts/crack_sublime/" class="next" rel="next" title="破解Sublime Text这个软件">破解Sublime Text这个软件<i class="fas fa-angle-right fa-fw" aria-hidden="true"></i></a></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.120.4">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw" aria-hidden="true"></i> LoveIt</a>
                </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw" aria-hidden="true"></i><span itemprop="copyrightYear">2024</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="https://xzap.gitee.io" target="_blank">xzap</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw" aria-hidden="true"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw" aria-hidden="true"></i>
            </a>
        </div><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/autocomplete.js@0.38.1/dist/autocomplete.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lunr@2.3.9/lunr.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lazysizes@5.3.1/lazysizes.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":50},"comment":{},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
